package com.ctsi.system.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.system.domain.DictionaryTreeData;
import com.ctsi.system.domain.DictionaryTreeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * DictionaryTreeType Service 类
 *
 * @author liuhx
 * @description DictionaryTreeType
 * @created Mon Sep 10 05:06:08 CST 2018
 */
@Service
public class DictionaryTreeTypeService {
    private static final Logger logger = LoggerFactory.getLogger(DictionaryTreeTypeService.class);
    @Autowired
    private MybatisGenericDao dao;

    public void setDao(MybatisGenericDao dao) {
        this.dao = dao;
    }

    /**
     * 判断字典树类型是否有子节点  selectDictTreeTypeIsLeaf
     */
    public Object selectDictTreeTypeIsLeaf(DictionaryTreeData dictionaryTreeData) {
        logger.debug("selectDictTreeTypeIsLeaf {}", dictionaryTreeData);
        return dao.queryForObject(DictionaryTreeType.class.getName() + ".selectDictTreeTypeIsLeaf", dictionaryTreeData);
    }

    /**
     * 根据id查询详情
     */
    public DictionaryTreeType selectDictTreeTypeById(String id) {
        logger.debug("selectDictTreeTypeById {}", id);
        return (DictionaryTreeType) dao.queryForObject(DictionaryTreeType.class.getName() + ".selectDictTreeTypeById", id);
    }

    /**
     * 添加
     */
    public void insertDictionaryTreeType(DictionaryTreeType dictionaryTreeType) {
        if (UtilValidate.isEmpty(dictionaryTreeType.getId())) {
            dictionaryTreeType.setId(UUIDGenerator.getId());
        }
        logger.debug("insert {}", dictionaryTreeType);
        dao.insert(dictionaryTreeType);
    }

    /**
     * 动态更新
     */
    public int updateDictionaryTreeTypeByPKSelective(DictionaryTreeType dictionaryTreeType) {
        logger.debug("updateByPrimaryKeySelective {}", dictionaryTreeType);
        return dao.update(DictionaryTreeType.class.getName() + ".updateByPrimaryKeySelective", dictionaryTreeType);
    }

    /**
     * 更新
     */
    public int updateDictionaryTreeType(DictionaryTreeType dictionaryTreeType) {
        logger.debug("update {}", dictionaryTreeType);
        return dao.update(dictionaryTreeType);
    }


    public DictionaryTreeType editDictionaryTreeTypeById(String iD) {
        if (UtilValidate.isEmpty(iD)) {
            return null;
        }
        logger.debug("editById {}", iD);
        return (DictionaryTreeType) dao.queryForObject(DictionaryTreeType.class.getName() + ".edit", iD);
    }

    /**
     * 根据ID查找 DictionaryTreeType对象
     */
    public DictionaryTreeType findDictionaryTreeTypeById(String iD) {
        if (UtilValidate.isEmpty(iD)) {
            return null;
        }
        logger.debug("findById {}", iD);
        return dao.get(DictionaryTreeType.class, iD);
    }

    /**
     * 删除DictionaryTreeType对象
     */
    public int removeDictionaryTreeType(String id) {
        if (UtilValidate.isNotEmpty(id)) {
            return dao.delete(DictionaryTreeType.class.getName() + ".delete", id);
        }
        return 0;
    }

    /**
     * 详细页查询
     */
    public Map<String, Object> findByDetail(String iD) {
        return (Map<String, Object>) dao.queryForObject(DictionaryTreeType.class.getName() + ".findByDetail", iD);
    }

    /**
     * 多条件查询结果
     */
    public Page<DictionaryTreeType> findByMulitCondition(Map<String, Object> param, int start, int pageSize) {
        logger.debug("findByMulitCondition {}", param);
        if (pageSize < 0 || pageSize > 2000) {
            pageSize = Page.DEFAULT_PAGE_SIZE;
        }
        if (start != -1) {
            return dao.queryPage(DictionaryTreeType.class.getName() + ".selectMulitCondition", param, start, pageSize);
        } else {
            throw new RuntimeException("参数不正确 !!");
        }
    }

    /**
     * 多条件查询结果不分页
     */
    public List<?> find(Map<String, Object> map) {
        logger.debug("find {}", map);
        return dao.queryForList(DictionaryTreeType.class.getName() + ".selectByMap", map);
    }

}
